package com.ef.service.impl;

import java.util.Date;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.ef.dao.CorpPayDao;
import com.ef.domain.CorpContract;
import com.ef.domain.CorpPayHistory;
import com.ef.domain.Leads;
import com.ef.service.CorpPayService;
import com.ef.util.CalendarUtil;

public class CorpPayServiceImpl extends BaseServiceImpl implements CorpPayService {

	private CorpPayDao corpPayDao;

 
	public List<CorpPayHistory> findByContract(CorpContract contract){
		return corpPayDao.findByContract(contract);
	}
	
	public void saveOrUpdate(CorpPayHistory entity){
		corpPayDao.saveOrUpdate(entity);
	}

	public CorpPayDao getCorpPayDao() {
		return corpPayDao;
	}

	public void setCorpPayDao(CorpPayDao corpPayDao) {
		this.corpPayDao = corpPayDao;
	}

 
	public List<CorpPayHistory> findByPayTime(Date start,Date end){
		DetachedCriteria criterion = DetachedCriteria.forClass(CorpPayHistory.class);
		if(start!=null){
	    	criterion.add(Restrictions.ge("payTime", CalendarUtil.getBeginOfDay(start)));
		}
		if(end!=null){
			CalendarUtil.getEndOfDay(end);
			criterion.add(Restrictions.le("payTime", CalendarUtil.getEndOfDay(end)));
		}
		criterion.addOrder(Order.asc("payTime")) ;
		return corpPayDao.findAllByCriteria(criterion);
	}
}
